/**
 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.library.slayer.service.impl;

import java.util.Date;
import java.util.List;

import com.library.slayer.model.Book;
import com.library.slayer.model.impl.BookImpl;
import com.library.slayer.service.base.BookLocalServiceBaseImpl;
import com.liferay.portal.kernel.dao.orm.DynamicQuery;
import com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil;
import com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil;
import com.liferay.portal.kernel.exception.SystemException;

/**
 * The implementation of the book local service.
 *
 * <p>
 * All custom service methods should be put in this class. Whenever methods are added, rerun ServiceBuilder to copy their definitions into the {@link com.library.slayer.service.BookLocalService} interface.
 * </p>
 *
 * <p>
 * Never reference this interface directly. Always use {@link com.library.slayer.service.BookLocalServiceUtil} to access the book local service.
 * </p>
 *
 * <p>
 * This is a local service. Methods of this service will not have security checks based on the propagated JAAS credentials because this service can only be accessed from within the same VM.
 * </p>
 *
 * @author Ahmed Hasan
 * @see com.library.slayer.service.base.BookLocalServiceBaseImpl
 * @see com.library.slayer.service.BookLocalServiceUtil
 */
public class BookLocalServiceImpl extends BookLocalServiceBaseImpl {
	public Book create(String bookTitle, String author) throws SystemException {
		
		Book book = new BookImpl();
		book.setBookTitle(bookTitle);
		book.setAuthor(author);
		book.setDateAdded(new Date());
		
		try {
			book = addBook(book);
		} catch (SystemException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return book;
	}
	
	public List<Book> quickFind(String bookTitle) throws SystemException {
		return bookPersistence.findByBookTitle(bookTitle);
	}
	
	public List<Book> search(String bookTitle) throws SystemException {
		
		//DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(Book.class);
		
		//dynamicQuery.add(PropertyFactoryUtil.forName("bookTitle").like("%" + bookTitle + "%"));
		
		// return dynamicQuery(dynamicQuery);
		
		return bookFinder.getBooks("%" + bookTitle + "%");
	}
}